package cn.yunhe.entity.impl;

import cn.yunhe.entity.PhoneBiz;
import cn.yunhe.excep.OutOfStockException;
import org.springframework.stereotype.Component;

@Component
public class PhoneBizImpl implements PhoneBiz {
    int num;//库存

    @Override
    public void buyPhone(int num) {
        System.out.println("预备购入" + num + "台新机");
        this.num+=num;
    }

    @Override
    public void salePhone(int num) throws OutOfStockException {
        if (this.num < num) {
            throw new OutOfStockException("库存不足,需要"+num+"部手机,库存现有"+this.num+"部");
        }
        System.out.println("预备出售" + num + "台新机");
    }


}
